// add by yanyj 20180731 start
// 注记图层

class StampLayer extends BaseLayer {
    constructor(props) {
        super(props);
        // 设置feature的类型
        this.featureType = 'stamp';
        // 设置state
        this.state = new State({}, {});
        this.fetch = new Fetch(pageLogic.initData.restUrlPrefix);

        this.isMoved = false;
        this.newStampFeature = null;

        this.markMapClick = this._markMapClick();
        this.markPointerMove = this._markPointerMove();
    }

    // 初始化
    init() {
        // 初始化图层
        this.setLayer(new ol.layer.Vector({
            source: new ol.source.Vector({
                features: []
            }),
            style: new ol.style.Style({
                image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
                    anchor: [0.25, 20],
                    anchorXUnits: 'fraction',
                    anchorYUnits: 'pixels',
                    opacity: 0.95,
                    src:  '/ais/images/map-icons/stamp.png'
                })),
                stroke: new ol.style.Stroke({
                    width: 3,
                    color: [255, 0, 0, 1]
                }),
                fill: new ol.style.Fill({
                    color: [0, 0, 255, 0.6]
                })
            })
        }));

        this.register();

        return this;
    }

    //事件注册
    register() {
        let _this = this;
        // stampLayer图层勾选
        $('#stampLayer').on('click', function () {
            if($(this).prop('checked')) {
                $('#stampLayerOption').show();
            } else {
                $('#stampLayerOption').hide();
            }
        });

        // 添加新的标记点
        $('#addStamp').on('click', function () {
            _this.isMoved = true;
            _this.newStampFeature = new ol.Feature(new ol.geom.Point([0, 0]));
            _this.newStampFeature.new = true;
            _this.newStampFeature.type = _this.featureType;
            _this.map.addFeatures(_this.layer, [_this.newStampFeature]);

            _this.map.getMap().on('pointermove', _this.markPointerMove);
        })
    }

    _markPointerMove() {
        let _this = this;
       return function (evt) {
           _this.newStampFeature.getGeometry().setCoordinates(evt.coordinate);
           if (!_this.isMoved) {
               _this.map.getMap().on('click', _this.markMapClick);
               _this.isMoved = true;
           }
       }
    }

    _markMapClick() {
        let _this = this;

        return function (evt) {
            _this.map.getMap().un('click', _this.markMapClick);
            // showPopup('markOver', pointFeature);

            _this.map.getMap().un('pointermove', _this.markPointerMove);
        };
    }

    getClickFeatureEvent() {
        return function (feature, coordinate) {
            if(feature.new) {
                return ;
            }
        }
    }

    // 信息弹出层
    showOverLayer(position, data, action) {

    }


}
// add by yanyj 20180731 end